home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / TIMER.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  3KB  |  97 lines

  1. #ifndef _LINUX_TIMER_H
  2. #define _LINUX_TIMER_H
  3.  
  4. /*
  5.  * Old-style timers. Please don't use for any new code.
  6.  *
  7.  * Numbering of these timers should be consecutive to minimize
  8.  * processing delays. [MJ]
  9.  */
  10.  
  11. #define BLANK_TIMER    0    /* Console screen-saver */
  12. #define BEEP_TIMER    1    /* Console beep */
  13. #define RS_TIMER    2    /* RS-232 ports */
  14. #define SWAP_TIMER    3    /* Background pageout */
  15. #define BACKGR_TIMER    4    /* io_request background I/O */
  16. #define HD_TIMER    5    /* Old IDE driver */
  17. #define FLOPPY_TIMER    6    /* Floppy */
  18. #define QIC02_TAPE_TIMER 7    /* QIC 02 tape */
  19. #define MCD_TIMER    8    /* Mitsumi CDROM */
  20. #define GSCD_TIMER    9    /* Goldstar CDROM */
  21. #define COMTROL_TIMER    10    /* Comtrol serial */
  22. #define DIGI_TIMER    11    /* Digi serial */
  23. #define GDTH_TIMER    12    /* Ugh - gdth scsi driver */
  24.  
  25. #define COPRO_TIMER    31    /* 387 timeout for buggy hardware (boot only) */
  26.  
  27. struct timer_struct {
  28.     unsigned long expires;
  29.     void (*fn)(void);
  30. };
  31.  
  32. extern unsigned long timer_active;
  33. extern struct timer_struct timer_table[32];
  34.  
  35. /*
  36.  * This is completely separate from the above, and is the
  37.  * "new and improved" way of handling timers more dynamically.
  38.  * Hopefully efficient and general enough for most things.
  39.  *
  40.  * The "hardcoded" timers above are still useful for well-
  41.  * defined problems, but the timer-list is probably better
  42.  * when you need multiple outstanding timers or similar.
  43.  *
  44.  * The "data" field is in case you want to use the same
  45.  * timeout function for several timeouts. You can use this
  46.  * to distinguish between the different invocations.
  47.  */
  48. struct timer_list {
  49.     struct timer_list *next; /* MUST be first element */
  50.     struct timer_list *prev;
  51.     unsigned long expires;
  52.     unsigned long data;
  53.     void (*function)(unsigned long);
  54. };
  55.  
  56. extern void add_timer(struct timer_list * timer);
  57. extern int  del_timer(struct timer_list * timer);
  58.  
  59. /*
  60.  * mod_timer is a more efficient way to update the expire field of an
  61.  * active timer (if the timer is inactive it will be activated)
  62.  * mod_timer(a,b) is equivalent to del_timer(a); a->expires = b; add_timer(a)
  63.  */
  64. void mod_timer(struct timer_list *timer, unsigned long expires);
  65.  
  66. extern void it_real_fn(unsigned long);
  67.  
  68. extern inline void init_timer(struct timer_list * timer)
  69. {
  70.     timer->next = NULL;
  71.     timer->prev = NULL;
  72. }
  73.  
  74. extern inline int timer_pending(struct timer_list * timer)
  75. {
  76.     return timer->prev != NULL;
  77. }
  78.  
  79. /*
  80.  *    These inlines deal with timer wrapping correctly. You are 
  81.  *    strongly encouraged to use them
  82.  *    1. Because people otherwise forget
  83.  *    2. Because if the timer wrap changes in future you wont have to
  84.  *       alter your driver code.
  85.  *
  86.  * Do this with "<0" and ">=0" to only test the sign of the result. A
  87.  * good compiler would generate better code (and a really good compiler
  88.  * wouldn't care). Gcc is currently neither.
  89.  */
  90. #define time_after(a,b)        ((long)(b) - (long)(a) < 0)
  91. #define time_before(a,b)    time_after(b,a)
  92.  
  93. #define time_after_eq(a,b)    ((long)(a) - (long)(b) >= 0)
  94. #define time_before_eq(a,b)    time_after_eq(b,a)
  95.  
  96. #endif
  97.